BackForward
/*-------------------------------------<-- Start of Header -->-------------------------------------\
| Version:   1.0                                                                                   |
| Author:    Duo Zhou                                                                              |
| Title:     Statistician                                                                          |
| Date:      April 15, 2002                                                                        |
| File Path: C:\Programs\StatSoft\SAS Institute\SAS\MyOwnSetting\sasmacro\GenHeader.sas            |
|---------------------------------------<-- End of Header -->--------------------------------------|
|--------------------------------------------------------------------------------------------------|
|-----------------------------------<-- Start of Description -->-----------------------------------|
| Purpose:   Generate Program Header for Statistics Programs Validation                            |
|------------------------------------<-- End of Description -->------------------------------------|
|--------------------------------------------------------------------------------------------------|
|-----------------------------------<-- Start of Parameters -->----------------------------------- |
| Parameters:                                                                                      |
|    filename   - Program Name                                                                     |
|    path       - path of the file                                                                 |
|    tofile     - write the header to the file you just listed as path; Note: the program will     |
|                 read the original file, and append a header at front, then write everything      |
|                 back. Be careful about this option, it will overwrite the original files. If     |
|                 error occurs, the original files will be lost permanently.                       |
|    version    - Version of the file                                                              |
|    author     - Author of the file                                                               |
|    title      - Title of the Author                                                              |
|    date       - Date of the program                                                              |
|    lib        - Libraries defined in the program. Note: different libraries need to be           |
|                 defined like this (lib1 c:\temp\                                                 |
|    lib2       - temp)                                                                            |
|    infile     - Input Files, including datasets and documents. Note: different type of files     |
|                 need to be defined like this (Indata: acedcrf.impl acedcrf.ae                    |
|    Infile     - temp\temp.doc ...), all subsections separated by the PHI delimiter will be       |
|                 starting from a different line                                                   |
|    outfile    - Output Files, including datasets and documents Note: this parameter should look  |
|                 like the above parameter, comment - Comments, Notes and References Note: the     |
|                 parameter should look like the above parameter too                               |
|------------------------------------<-- End of Parameters -->------------------------------------ |
|--------------------------------------------------------------------------------------------------|
|-------------------------------------<-- Start of Comments -->------------------------------------|
| Comments:                                                                                        |
|    Usage: GenHeader(filename=, path=, tofile=F, version=1.0, author=Duo Zhou,                    |
|    title=Statistician, date=, study=, purpose=, macropara=, lib=, infile=,                       |
|    outfile=, comment=)                                                                           |
\--------------------------------------<-- End of Comments -->------------------------------------*/
%macro GenHeader(filename=, path=, tofile=F, version=1.0, author=Duo Zhou, title=Statistician,
              date=(%sysfunc(date(), worddate20.)), study=, purpose=, macropara=(:|:),
              lib=(|), infile=(|), outfile=(|), comment=(|));
/*---------------------------------------------\
| Copy Right: Duo Zhou;                        |
| Created: 4-14-2001 4:16pm;                   |
| Purpose: Generate Program Headers;           |
\---------------------------------------------*/
%local linesize _substr1_ _currstr1_ _subscnt1_ _wordsub1_ _lines1_ _substr2_
       _currstr2_ _subscnt2_ _wordsub2_ _lines2_ _paraname_ _substr3_
       _currstr3_ _subscnt3_ _wordsub3_ _lines3_ _npara_ _parameter_ _nlib_
       _libname_ _substr4_ _currstr4_ _subscnt4_ _wordsub4_ _lines4_
       _library_ _substr5_ _currstr5_ _subscnt5_ _wordsub5_ _lines5_
       _nfile_ _filename_ _filel_ _dlm_ _substr6_ _currstr6_ _subscnt6_
       _wordsub6_ _lines6_ _nfilec_ _filecname_ _filec_ _dlmc_ _substr7_
       _currstr7_ _subscnt7_ _wordsub7_ _lines7_ _ncomm_ _commcnt_
       _commitem_ _dlmcomm_ _tmplast_; %let _tmplast_=&syslast;
%let linesize = %SYSFUNC(GETOPTION(linesize));
%let pagesize = %SYSFUNC(GETOPTION(pagesize));
options ls=100 nocenter ps=1024;
%if (%length(&path) >3) %then %do;
   %if (%quote(&path) ne) %then %let path=%sysfunc(dequote(&path));
   %if (%quote(&filename) ne) %then %let filename=%sysfunc(dequote(&filename));
   %else %if (%quote(&path) ne) %then %let filename=%sysfunc(reverse(%qscan(%quote(%sysfunc(reverse(&path))), 1, %str(\))));
   %if (%sysfunc(fileexist(&path))) %then %do;
      %if (%quote(%upcase(%substr(%quote(&path),%eval(%length(&path)-3),4))) eq %quote(.SAS)) %then %do;
         %let filepath=%substr(%quote(&path), 1, %eval(%length(&path)-%length(&filename)));
         filename _pfile_ "&path";
         %if (%index(%quote(%upcase(&tofile)), T)) %then %do;
         DATA _tmp1_;
         infile _pfile_ length=linelen end=done;
         length linecontent $ 2000;
         do while(not done);
            input @1 linecontent $ varying2000. linelen;
            output;
         end;
         keep linecontent;
         run;
         data _null_;
            file _pfile_;
            set _tmp1_;
         %end;
         %else %do;
            data _null_;
               file print; linecontent = ' ';
         %end;
      %end;
      %else %do;
         %put ==> Alert! Can not find File "&path"!;
         data _null_;
            file print; linecontent = ' ';
      %end;
   %end;
   %else %do;
      %put ==> Alert! File "&filepath" does not exist!;
      data _null_;
         file print; linecontent = ' ';
   %end;
%end;
%else %do;
   %put ==> Alert! File "&filepath" does not exist!;
   data _null_;
      file print; linecontent = ' ';
%end;
   length str1 str2 $2000.;
   retain position 14;
   if _n_=1 then do;
      put #1 '/*' 37*'-' '<-- Start of Header -->' 37*'-' @100 '\';
      %if (%length(&filename) gt 3) %then %do;
      %let filename=%sysfunc(tranwrd(%nrbquote(&filename), %str(%"), %str(%')));
      str1 ="Program: ";
      str2= trimn(left("&filename"));
      put '| ' str1 @position str2 @100 '|';
      %end;
      %if (%length(&version) gt 0) %then %do;
      str1="Version: "; str2=trimn(left("&version"));
      put '| ' str1 @position str2 @100 '|';
      %end;
      %if (%length(&author) gt 0) %then %do;
      str1="Author: "; str2=trimn(left("&author"));
      put '| ' str1 @position str2 @100 '|';
      %end;
      %if (%length(&title) gt 0) %then %do;
      str1="Title: "; str2=trimn(left("&title"));
      put '| ' str1 @position str2 @100 '|';
      %end;
      %if (%length(&date) gt 3) %then %do;
      %let date=%sysfunc(compress(&date, ')('));
      str1="Date: "; str2=trimn(left("&date"));
      put '| ' str1 @position str2 @100 '|';
      %end;
      %if (%length(&study) gt 1) %then %do;
      str1="Study: "; str2=trimn(left("&study"));
      put '| ' str1 @position str2 @100 '|';
      %end;
      %if (%length(&path) gt 2) %then %do;
         str1="File Path: ";
         %let _lines1_=1;
         %do %while(%length(&path)>86);
            %let _substr1_=%substr(%quote(%left(&path)), 1, 86);
            %if (%quote(%substr(%quote(%left(&path)), 87, 1)) eq %quote(\)) %then %do;
               %let path=%substr(%quote(%left(&path)), 87, %eval(%length(&path)-86));
               %let _currstr1_=&_substr1_;
            %end;
            %else %do;
               %let _currstr1_=; %let _subscnt1_=0;
               %do %while(%length(%nrbquote(%scan(&_substr1_, %eval(&_subscnt1_+1), %str(\)))));
                  %let _subscnt1_=%eval(&_subscnt1_+1);
                  %let _wordsub1_=%qscan(&_substr1_, &_subscnt1_, %str(\));
                  %if (%length(%nrbquote(%scan(&_substr1_, %eval(&_subscnt1_+1), %str(\))))) %then %do;
                     %let _currstr1_=%trim(%left(&_currstr1_))%trim(%left(&_wordsub1_))\;
                     %let path=%substr(%quote(%left(&path)), %eval(%length(&_wordsub1_)+2), %eval(%length(&path)-%eval(%length(&_wordsub1_)+1)));
                  %end;
               %end;
            %end;
            str2=trimn(left("&_currstr1_"));
            %if (&_lines1_ eq 1) %then %do;
               put '| ' str1 @position str2 @100 '|';
            %end;
            %else %do;
               put '|'  @position str2 @100 '|';
            %end;
            %let _lines1_=%eval(&_lines1_+1);
         %end;
         str2=trimn(left("&path"));
         %if (&_lines1_ eq 1) %then %do;
            put '| ' str1 @position str2 @100 '|';
         %end;
         %else %do;
            put '|'  @position str2 @100 '|';
         %end;
      %end;
      put '|' 39*'-' '<-- End of Header -->' 38*'-' @100 '|';
      put '|' 98*'-' '|';
      %if (%length(%nrbquote(&purpose)) gt 3) %then %do; 
         put '|' 35*'-' '<-- Start of Description -->' 35*'-' @100 '|';
         str1="Purpose: ";
         %if (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&purpose))))), %str(%()) eq 1) and
             (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(%sysfunc(reverse(%nrbquote(&purpose)))))))), %str(%))) eq 1) %then %do;
            %if (%sysfunc(rxmatch(%sysfunc(rxparse($(1))),%nrbquote(&purpose))) gt 1) %then %let purpose=%nrbquote(%substr(%nrbquote(&purpose), 2, %eval(%length(%nrbquote(&purpose))-2)));
            %else %let purpose=%nrbquote(%substr(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&purpose))))), 2, %eval(%length(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&purpose))))))-2)));
         %end;
         %if ((%index(%nrbquote(&purpose),%str(%')) and %index(%nrbquote(&purpose),%str(%')<2))
                or (%index(%nrbquote(&purpose),%str(%")) and  %index(%nrbquote(&purpose),%str(%")) lt 2)) %then %do;
            %let purpose=%nrbquote(%sysfunc(dequote(&purpose)));
         %end;
         %let purpose=%bquote(%sysfunc(tranwrd(%nrbquote(&purpose), %str(%(), %str(À))));
         %let purpose=%bquote(%sysfunc(tranwrd(%nrbquote(&purpose), %str(%)), %str(Á))));
         %let purpose=%bquote(%sysfunc(tranwrd(%nrbquote(&purpose), %str(%%), %str(Â))));
         %let purpose=%bquote(%sysfunc(tranwrd(%nrbquote(&purpose), %str(%'), %str(¸))));
         %let purpose=%bquote(%sysfunc(tranwrd(%nrbquote(&purpose), %str(%"), %str(¹))));
         %let purpose=%qcmpres(&purpose); 
         %if (%index(%nrbquote(%sysfunc(reverse(%nrbquote(&purpose)))), %str(;)) ne 1) %then %let purpose=&purpose%str(;); 
         %let _lines2_=1;
         %do %while(%length(&purpose)>86);
            %let _substr2_=%substr(%quote(%left(%quote(&purpose))), 1, 86);
            %if (%quote(%substr(%quote(%left(%quote(&purpose))), 87, 1)) eq %quote( )) %then %do;
               %let purpose=%substr(%quote(%left(%quote(&purpose))), 87, %eval(%length(&purpose)-86));
               %let _currstr2_=&_substr2_;
            %end;
            %else %do;
               %let _currstr2_=; %let _subscnt2_=0;
               %do %while(%length(%quote(%qscan(%quote(&_substr2_), %eval(&_subscnt2_+1), %str( )))));
                  %let _subscnt2_=%eval(&_subscnt2_+1);
                  %let _wordsub2_=%qscan(%quote(&_substr2_), &_subscnt2_, %str( ));
                  %if (%length(%quote(%qscan(%quote(&_substr2_), %eval(&_subscnt2_+1), %str( ))))) %then %do;
                     %let _currstr2_=%trim(%quote(%left(%quote(&_currstr2_))))%str( )%trim(%quote(%left(%quote(&_wordsub2_))));
                     %let purpose=%left(%quote(&purpose));
                     %let purpose=%substr(%quote(&purpose), %eval(%length(&_wordsub2_)+2), %eval(%eval(%length(&purpose)-%length(&_wordsub2_))-1));
                  %end;
               %end;
            %end;
            str2=trimn(left("&_currstr2_"));
            str2=tranwrd(str2, '¸', "'");
            str2=tranwrd(str2, '¹', '"');
            str2=tranwrd(str2, 'Â', '%');
            str2=tranwrd(str2, 'À', '(');
            str2=tranwrd(str2, 'Á', ')');
            %if (&_lines2_ eq 1) %then %do;
               put '| ' str1 @position str2 @100 '|';
            %end;
            %else %do;
               put '|'  @position str2 @100 '|';
            %end;
            %let _lines2_=%eval(&_lines2_+1);
         %end;
         str2=trimn(left("&purpose"));
         str2=tranwrd(str2, '¸', "'");
         str2=tranwrd(str2, '¹', '"');
         str2=tranwrd(str2, 'Â', '%');
         str2=tranwrd(str2, 'À', '(');
         str2=tranwrd(str2, 'Á', ')');
         %if (&_lines2_ eq 1) %then %do;
            put '| ' str1 @position str2 @100 '|';
         %end;
         %else %do;
            put '|'  @position str2 @100 '|';
         %end;
      put '|' 36*'-' '<-- End of Description -->' 36*'-' @100 '|';
      put '|' 98*'-' '|';
      %end; 
      %if (%length(%nrbquote(¯opara)) gt 5) %then %do;
         put '|' 35*'-' '<-- Start of Parameters -->' 35*'-' @100 '|';
         str1="Parameters: "; put '| '  str1 @100 '|';
         %if (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(¯opara))))), %str(%()) eq 1) and
             (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(%sysfunc(reverse(%nrbquote(¯opara)))))))), %str(%))) eq 1) %then %do;
            %if (%sysfunc(rxmatch(%sysfunc(rxparse($(1))),%nrbquote(¯opara))) gt 1) %then %let macropara=%nrbquote(%substr(%nrbquote(¯opara), 2, %eval(%length(%nrbquote(¯opara))-2)));
            %else %let macropara=%nrbquote(%substr(%nrbquote(%trim(%nrbquote(%left(%nrbquote(¯opara))))), 2, %eval(%length(%nrbquote(%trim(%nrbquote(%left(%nrbquote(¯opara))))))-2)));
         %end;
         %if ((%index(%nrbquote(¯opara),%str(%')) and %index(%nrbquote(¯opara),%str(%')<2))
                or (%index(%nrbquote(¯opara),%str(%")) and  %index(%nrbquote(¯opara),%str(%")) lt 2)) %then %do;
            %let macropara=%nrbquote(%sysfunc(dequote(¯opara)));
         %end;
         %let macropara=%bquote(%sysfunc(tranwrd(%nrbquote(¯opara), %str(%(), %str(À))));
         %let macropara=%bquote(%sysfunc(tranwrd(%nrbquote(¯opara), %str(%)), %str(Á))));
         %let macropara=%bquote(%sysfunc(tranwrd(%nrbquote(¯opara), %str(%%), %str(Â))));
         %let macropara=%bquote(%sysfunc(tranwrd(%nrbquote(¯opara), %str(%'), %str(¸))));
         %let macropara=%bquote(%sysfunc(tranwrd(%nrbquote(¯opara), %str(%"), %str(¹))));
         %let macropara=%qcmpres(¯opara);
         %let _npara_=0;
         %do %while(%length(%quote(%qscan(%quote(¯opara), %eval(&_npara_+1), %str(|)))));
            %let _npara_=%eval(&_npara_+1);
            %let _parameter_=%qscan(%quote(¯opara), &_npara_, %str(|));
            %if (%index(%nrbquote(%sysfunc(reverse(%nrbquote(&_parameter_)))), %str(;)) ne 1) %then %let _parameter_=&_parameter_%str(;); 
            %let _paraname_ =%qscan(%quote(&_parameter_), 1 , %str( -:));
            %let _parameter_=%left(%quote(%substr(%quote(&_parameter_), %eval(%length(&_paraname_)+2), %eval(%eval(%length(&_parameter_)-%length(&_paraname_))-1))));
            %if (%index(%quote(&_parameter_),%str(-)) and %index(%quote(&_parameter_),%str(-)) lt 5) %then %do;
                %let _parameter_=%left(%quote(%substr(%quote(&_parameter_), %eval(%index(%quote(&_parameter_), %str(-))+2), %eval(%eval(%length(&_parameter_)-%index(%quote(&_parameter_), %str(-)))-1))));
            %end;
            %else %if (%index(%quote(&_parameter_),%str(:)) and %index(%quote(&_parameter_),%str(:)) lt 5) %then %do;
                %let _parameter_=%left(%quote(%substr(%quote(&_parameter_), %eval(%index(%quote(&_parameter_), %str(:))+2), %eval(%eval(%length(&_parameter_)-%index(%quote(&_parameter_), %str(:)))-1))));
            %end;
            %let _lines3_=1;
            %do %while(%length(&_parameter_)>79);
               %let _substr3_=%substr(%quote(%left(%quote(&_parameter_))), 1, 79);
               %if (%quote(%substr(%quote(%left(%quote(&_parameter_))), 80, 1)) eq %quote( )) %then %do;
                  %let _parameter_=%substr(%quote(%left(%quote(&_parameter_))), 80, %eval(%length(&_parameter_)-79));
                  %let _currstr3_=&_substr3_;
               %end;
               %else %do;
                  %let _currstr3_=; %let _subscnt3_=0;
                  %do %while(%length(%quote(%qscan(%quote(&_substr3_), %eval(&_subscnt3_+1), %str( )))));
                     %let _subscnt3_=%eval(&_subscnt3_+1);
                     %let _wordsub3_=%qscan(%quote(&_substr3_), &_subscnt3_, %str( ));
                     %if (%length(%quote(%qscan(%quote(&_substr3_), %eval(&_subscnt3_+1), %str( ))))) %then %do;
                        %let _currstr3_=%trim(%quote(%left(%quote(&_currstr3_))))%str( )%trim(%quote(%left(%quote(&_wordsub3_))));
                        %let _parameter_=%left(%quote(&_parameter_));
                        %let _parameter_=%substr(%quote(&_parameter_), %eval(%length(&_wordsub3_)+2), %eval(%eval(%length(&_parameter_)-%length(&_wordsub3_))-1));
                     %end;
                  %end;
               %end;
               str2=trimn(left("&_currstr3_"));
               str2=tranwrd(str2, '¸', "'");
               str2=tranwrd(str2, '¹', '"');
               str2=tranwrd(str2, 'Â', '%');
               str2=tranwrd(str2, 'À', '(');
               str2=tranwrd(str2, 'Á', ')');
               %if (&_lines3_ eq 1) %then %do;
                  put '|' @6 "%trim(%quote(%left(%quote(&_paraname_))))" @17 '-' @19 str2 @100 '|';
               %end;
               %else %do;
                  position2=19;
                  put '|'  @position2 str2 @100 '|';
               %end;
               %let _lines3_=%eval(&_lines3_+1);
            %end;
            str2=trimn(left("&_parameter_"));
            str2=tranwrd(str2, '¸', "'");
            str2=tranwrd(str2, '¹', '"');
            str2=tranwrd(str2, 'Â', '%');
            str2=tranwrd(str2, 'À', '(');
            str2=tranwrd(str2, 'Á', ')');
            %if (&_lines3_ eq 1) %then %do;
               put '|' @6 "%trim(%quote(%left(%quote(&_paraname_))))" @17 '-' @19 str2 @100 '|';
            %end;
            %else %do;
               position2=19;
               put '|'  @position2 str2 @100 '|';
            %end;
         %end;
      put '|' 36*'-' '<-- End of Parameters -->' 36*'-' @100 '|';
      put '|' 98*'-' '|';
      %end;
      %if (%length(%nrbquote(&lib)) gt 3) %then %do; 
         put '|' 32*'-' '<-- Start of Library References -->' 32*'-' @100 '|';
         str1="Library References: "; put '| '  str1 @100 '|';
         %if (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&lib))))), %str(%()) eq 1) and
             (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(%sysfunc(reverse(%nrbquote(&lib)))))))), %str(%))) eq 1) %then %do;
            %if (%sysfunc(rxmatch(%sysfunc(rxparse($(1))),%nrbquote(&lib))) gt 1) %then %let lib=%nrbquote(%substr(%nrbquote(&lib), 2, %eval(%length(%nrbquote(&lib))-2)));
            %else  %let lib=%nrbquote(%substr(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&lib))))), 2, %eval(%length(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&lib))))))-2)));
         %end;
         %if ((%index(%nrbquote(&lib),%str(%')) and %index(%nrbquote(&lib),%str(%')<2))
                or (%index(%nrbquote(&lib),%str(%")) and  %index(%nrbquote(&lib),%str(%")) lt 2)) %then %do;
            %let lib=%nrbquote(%sysfunc(dequote(&lib)));
         %end;
         %let lib=%bquote(%sysfunc(tranwrd(%nrbquote(&lib), %str(%(), %str(À))));
         %let lib=%bquote(%sysfunc(tranwrd(%nrbquote(&lib), %str(%)), %str(Á))));
         %let lib=%bquote(%sysfunc(tranwrd(%nrbquote(&lib), %str(%%), %str(Â))));
         %let lib=%bquote(%sysfunc(tranwrd(%nrbquote(&lib), %str(%'), %str(¸))));
         %let lib=%bquote(%sysfunc(tranwrd(%nrbquote(&lib), %str(%"), %str(¹))));
         %let lib=%qcmpres(&lib);
         %let _nlib_=0;
         %do %while(%length(%quote(%qscan(%quote(&lib), %eval(&_nlib_+1), %str(|)))));
            %let _nlib_=%eval(&_nlib_+1);
            %let _library_=%qscan(%quote(&lib), &_nlib_, %str(|));
            %if (%index(%nrbquote(%sysfunc(reverse(%nrbquote(&_library_)))), %str(;)) ne 1) %then %let _library_=&_library_%str(;); 
            %if (%index(%quote(&_library_), %quote(:))) %then %let _libdlm_=%nrbquote(:);
            %else %if (%index(%quote(&_library_), %quote(%)))) %then %let _libdlm_=%nrbquote());
            %else %if (%index(%quote(&_library_), %quote(-))) %then %let _libdlm_=%nrbquote(-);
            %else %let _libdlm_=%quote( );
            %let _libname_ =%qscan(%quote(&_library_), 1 , %nrbquote(&_libdlm_));
            %let _libname_=%bquote(%sysfunc(tranwrd(%nrbquote(&_libname_), %str(À), %str(%())));
            %let _libname_=%bquote(%sysfunc(tranwrd(%nrbquote(&_libname_), %str(Á), %str(%)))));
            %let _libname_=%bquote(%sysfunc(tranwrd(%nrbquote(&_libname_), %str(Â), %str(%%))));
            %let _libname_=%bquote(%sysfunc(tranwrd(%nrbquote(&_libname_), %str(¸), %str(%'))));
            %let _libname_=%bquote(%sysfunc(tranwrd(%nrbquote(&_libname_), %str(¹), %str(%"))));
            %let _library_=%left(%quote(%substr(%quote(&_library_), %eval(%length(&_libname_)+2), %eval(%eval(%length(&_library_)-%length(&_libname_))-1))));
            %let _dlm_=;
            %if (%index(%nrbquote(&lib),%str(\))) %then %do;
               %let _dlm_=%str(\);
            %end;
            %else %let _dlm_=%str(&_dlm_);
            %let _lines4_=1;
            %do %while(%length(&_library_)>81);
               %let _substr4_=%substr(%quote(%left(%quote(&_library_))), 1, 81);
               %if (%quote(%substr(%quote(%left(%quote(&_library_))), 82, 1)) eq %quote(&_dlm_)) %then %do;
                  %let _library_=%substr(%quote(%left(%quote(&_library_))), 82, %eval(%length(%left(%quote(&_library_)))-81));
                  %let _currstr4_=&_substr4_;
               %end;
               %else %do;
                  %let _currstr4_=; %let _subscnt4_=0;
                  %do %while(%length(%quote(%qscan(%quote(&_substr4_), %eval(&_subscnt4_+1), %str(&_dlm_)))));
                     %let _subscnt4_=%eval(&_subscnt4_+1);
                     %let _wordsub4_=%qscan(%quote(&_substr4_), &_subscnt4_, %str(&_dlm_));
                     %if (%length(%quote(%qscan(%quote(&_substr4_), %eval(&_subscnt4_+1), %str(&_dlm_))))) %then %do;
                        %if (%quote(&_dlm_) eq %quote(\)) %then
                           %let _currstr4_=%trim(%quote(%left(%quote(&_currstr4_))))%trim(%quote(%left(%quote(&_wordsub4_))))%str(&_dlm_);
                        %else %let _currstr4_=%trim(%quote(%left(%quote(&_currstr4_))))%str(&_dlm_)%trim(%quote(%left(%quote(&_wordsub4_))));
                        %let _library_=%left(%quote(&_library_));
                        %let _library_=%substr(%quote(&_library_), %eval(%length(&_wordsub4_)+2), %eval(%eval(%length(&_library_)-%length(&_wordsub4_))-1));
                     %end;
                  %end;
               %end;
               str2=trimn(left("&_currstr4_"));
               str2=tranwrd(str2, '¸', "'");
               str2=tranwrd(str2, '¹', '"');
               str2=tranwrd(str2, 'Â', '%');
               str2=tranwrd(str2, 'À', '(');
               str2=tranwrd(str2, 'Á', ')');
               %if (&_lines4_ eq 1) %then %do;
                  put '|' @6 "%trim(%quote(%left(%quote(&_libname_))))" @17 '-' @19 str2 @100 '|';
               %end;
               %else %do;
                  position2=19;
                  put '|'  @position2 str2 @100 '|';
               %end;
               %let _lines4_=%eval(&_lines4_+1);
            %end;
            str2=trimn(left("&_library_"));
            str2=tranwrd(str2, '¸', "'");
            str2=tranwrd(str2, '¹', '"');
            str2=tranwrd(str2, 'Â', '%');
            str2=tranwrd(str2, 'À', '(');
            str2=tranwrd(str2, 'Á', ')');
            %if (&_lines4_ eq 1) %then %do;
               put '|' @6 "%trim(%quote(%left(%quote(&_libname_))))" @17 '-' @19 str2 @100 '|';
            %end;
            %else %do;
               position2=19;
               put '|'  @position2 str2 @100 '|';
            %end;
            /**** Loop 1 ****/
         %end;
      put '|' 33*'-' '<-- End of Library References -->' 32*'-' @100 '|';
      put '|' 98*'-' '|';
      %end; 
      %if (%length(%nrbquote(&infile)) gt 3) %then %do; 
         put '|' 35*'-' '<-- Start of Files Needed -->' 35*'-' @100 '|';
         str1="Files Needed: "; put '| '  str1 @100 '|'; 
         %if (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&infile))))), %str(%()) eq 1) and
             (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(%sysfunc(reverse(%nrbquote(&infile)))))))), %str(%))) eq 1) %then %do;
            %if (%sysfunc(rxmatch(%sysfunc(rxparse($(1))),%nrbquote(&infile))) gt 1) %then %let infile=%nrbquote(%substr(%nrbquote(&infile), 2, %eval(%length(%nrbquote(&infile))-2)));
            %else %let infile=%nrbquote(%substr(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&infile))))), 2, %eval(%length(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&infile))))))-2)));
         %end; 
         %if ((%index(%nrbquote(&infile),%str(%')) and %index(%nrbquote(&infile),%str(%')<2))
                or (%index(%nrbquote(&infile),%str(%")) and  %index(%nrbquote(&infile),%str(%")) lt 2)) %then %do;
            %let infile=%nrbquote(%sysfunc(dequote(&infile)));
         %end;
         %let infile=%bquote(%sysfunc(tranwrd(%nrbquote(&infile), %str(%(), %str(À))));
         %let infile=%bquote(%sysfunc(tranwrd(%nrbquote(&infile), %str(%)), %str(Á))));
         %let infile=%bquote(%sysfunc(tranwrd(%nrbquote(&infile), %str(%%), %str(Â))));
         %let infile=%bquote(%sysfunc(tranwrd(%nrbquote(&infile), %str(%'), %str(¸))));
         %let infile=%bquote(%sysfunc(tranwrd(%nrbquote(&infile), %str(%"), %str(¹))));
         %let infile=%qcmpres(&infile); 
         %let _nfile_=0; 
         %do %while(%length(%qscan(%quote(&infile), %eval(&_nfile_+1), %str(|))));
            %let _nfile_=%eval(&_nfile_+1);
            %let _filel_=%qscan(%quote(&infile), &_nfile_, %str(|)); 
            %if (%index(%nrbquote(%sysfunc(reverse(%nrbquote(&_filel_)))), %str(;)) ne 1) %then %let _filel_=&_filel_%str(;); 
            %let _slashposl_=%index(%nrbquote(&_filel_),%str(\)); 
            %if (&_slashposl_ ge 1) %then %do;
               %if (&_slashposl_ ge 93) %then %let _dlml_=%quote(\ );
               %else %let _dlml_=%quote(\);
            %end;
            %else %let _dlml_=%str( ); 
            %let _lines5_=1;
            %do %while(%length(&_filel_)>93);
               %let _substr5_=%substr(%quote(%left(%quote(&_filel_))), 1, 93); 
               %if (%quote(%substr(%quote(%left(%quote(&_filel_))), 94, 1)) eq %quote(&_dlm_)) %then %do;
                  %let _filel_=%substr(%quote(%left(%quote(&_filel_))), 94, %eval(%length(%left(%quote(&_filel_)))-93));
                  %let _currstr5_=&_substr5_; 
               %end;
               %else %do;
                  %let _currstr5_=; %let _subscnt5_=0;
                  %do %while(%length(%qscan(%quote(&_substr5_), %eval(&_subscnt5_+1), %str(&_dlml_))));
                     %let _subscnt5_=%eval(&_subscnt5_+1);
                     %let _wordsub5_=%qscan(%quote(&_substr5_), &_subscnt5_, %str(&_dlml_));
                     %if (%length(%quote(%qscan(%quote(&_substr5_), %eval(&_subscnt5_+1), %str(&_dlml_))))) %then %do;
                        %if (%index(%nrbquote(&_dlml_),%str(\))) and (&_slashposl_ lt 93) %then
                           %let _currstr5_=%trim(%quote(%left(%quote(&_currstr5_))))%trim(%quote(%left(%quote(&_wordsub5_))))\;
                        %else %if (%index(%nrbquote(&_dlml_),%str(\))) and ((%length(%trim(%quote(%left(%quote(&_currstr5_)))))<&_slashposl_) and (&_slashposl_>=93)) %then
                           %let _currstr5_=%trim(%quote(%left(%quote(&_currstr5_)))) %trim(%quote(%left(%quote(&_wordsub5_))));
                        %else %if (%index(%nrbquote(&_dlml_),%str(\))) and ((%length(%trim(%quote(%left(%quote(&_currstr5_)))))>=&_slashposl_) and (&_slashposl_>=93)) %then
                           %let _currstr5_=%trim(%quote(%left(%quote(&_currstr5_))))%trim(%quote(%left(%quote(&_wordsub5_))))\;
                        %else %let _currstr5_=%trim(%quote(%left(%quote(&_currstr5_))))%str(&_dlml_)%trim(%quote(%left(%quote(&_wordsub5_))));
                        %let _filel_=%left(%quote(&_filel_)); 
                        %let _filel_=%substr(%quote(&_filel_), %eval(%length(&_wordsub5_)+2), %eval(%eval(%length(&_filel_)-%length(&_wordsub5_))-1));
                     %end;
                  %end;
               %end; 
               str2=trimn(left("&_currstr5_"));
               str2=tranwrd(str2, '¸', "'");
               str2=tranwrd(str2, '¹', '"');
               str2=tranwrd(str2, 'Â', '%');
               str2=tranwrd(str2, 'À', '(');
               str2=tranwrd(str2, 'Á', ')');
               %if (&_lines5_ eq 1) %then %do;
                  put '|' @6 str2 @100 '|';
               %end;
               %else %do;
                  put '|'  @6 str2 @100 '|';
               %end;
               %let _lines5_=%eval(&_lines5_+1);
            %end; 
            str2=trimn(left("&_filel_"));
            str2=tranwrd(str2, '¸', "'");
            str2=tranwrd(str2, '¹', '"');
            str2=tranwrd(str2, 'Â', '%');
            str2=tranwrd(str2, 'À', '(');
            str2=tranwrd(str2, 'Á', ')');
            %if (&_lines5_ eq 1) %then %do;
               put '|' @6 str2 @100 '|';
            %end;
            %else %do;
               put '|' @6 str2 @100 '|';
            %end;
            %if (%length(%qscan(%quote(&infile), %eval(&_nfile_+1), %str(|)))) %then %do;
               put '|' 98*' ' '|';
            %end;
         %end;
      put '|' 36*'-' '<-- End of Files Needed -->' 35*'-' @100 '|';
      put '|' 98*'-' '|';
      %end; 
      %if (%length(%nrbquote(&outfile)) gt 3) %then %do;
         put '|' 35*'-' '<-- Start of Files Created -->' 34*'-' @100 '|';
         str1="Files Created: "; put '| '  str1 @100 '|';
         %if (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&outfile))))), %str(%()) eq 1) and
             (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(%sysfunc(reverse(%nrbquote(&outfile)))))))), %str(%))) eq 1) %then %do;
            %if (%sysfunc(rxmatch(%sysfunc(rxparse($(1))),%nrbquote(&outfile))) gt 1) %then %let outfile=%nrbquote(%substr(%nrbquote(&outfile), 2, %eval(%length(%nrbquote(&outfile))-2)));
            %else %let outfile=%nrbquote(%substr(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&outfile))))), 2, %eval(%length(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&outfile))))))-2)));
         %end;
         %if ((%index(%nrbquote(&outfile),%str(%')) and %index(%nrbquote(&outfile),%str(%')<2))
                or (%index(%nrbquote(&outfile),%str(%")) and  %index(%nrbquote(&outfile),%str(%")) lt 2)) %then %do;
            %let outfile=%nrbquote(%sysfunc(dequote(&outfile)));
         %end; 
         %let outfile=%bquote(%sysfunc(tranwrd(%nrbquote(&outfile), %str(%(), %str(À))));
         %let outfile=%bquote(%sysfunc(tranwrd(%nrbquote(&outfile), %str(%)), %str(Á))));
         %let outfile=%bquote(%sysfunc(tranwrd(%nrbquote(&outfile), %str(%%), %str(Â))));
         %let outfile=%bquote(%sysfunc(tranwrd(%nrbquote(&outfile), %str(%'), %str(¸))));
         %let outfile=%bquote(%sysfunc(tranwrd(%nrbquote(&outfile), %str(%"), %str(¹))));
         %let outfile=%qcmpres(&outfile);
         %let _nfilec_=0;
         %do %while(%length(%qscan(%quote(&outfile), %eval(&_nfilec_+1), %str(|))));
            %let _nfilec_=%eval(&_nfilec_+1);
            %let _filec_=%qscan(%quote(&outfile), &_nfilec_, %str(|));
            %if (%index(%nrbquote(%sysfunc(reverse(%nrbquote(&_filec_)))), %str(;)) ne 1) %then %let _filec_=&_filec_%str(;);
            %let _slashposc_=%index(%nrbquote(&_filec_),%str(\));
            %if (&_slashposc_ ge 1) %then %do;
               %if (&_slashposc_ ge 93) %then %let _dlmc_=%quote(\ );
               %else %let _dlmc_=%quote(\);
            %end; 
            %else %let _dlmc_=%quote( ); 
            %let _lines6_=1;
            %do %while(%length(&_filec_)>93);
               %let _substr6_=%substr(%quote(%left(%quote(&_filec_))), 1, 93);
               %if (%quote(%substr(%quote(%left(%quote(&_filec_))), 94, 1)) eq %quote(&_dlmc_)) %then %do;
                  %let _filec_=%substr(%quote(%left(%quote(&_filec_))), 94, %eval(%length(%left(%quote(&_filec_)))-93));
                  %let _currstr6_=&_substr6_;
               %end;
               %else %do;
                  %let _currstr6_=; %let _subscnt6_=0;
                  %do %while(%length(%qscan(%quote(&_substr6_), %eval(&_subscnt6_+1), %str(&_dlmc_))));
                     %let _subscnt6_=%eval(&_subscnt6_+1);
                     %let _wordsub6_=%qscan(%quote(&_substr6_), &_subscnt6_, %str(&_dlmc_));
                     %if (%length(%quote(%qscan(%quote(&_substr6_), %eval(&_subscnt6_+1), %str(&_dlmc_))))) %then %do;
                        %if (%index(%nrbquote(&_dlmc_),%str(\))) and (&_slashposc_ lt 93) %then
                           %let _currstr6_=%trim(%quote(%left(%quote(&_currstr6_))))%trim(%quote(%left(%quote(&_wordsub6_))))\;
                        %else %if (%index(%nrbquote(&_dlmc_),%str(\))) and ((%length(%trim(%quote(%left(%quote(&_currstr6_)))))<&_slashposc_) and (&_slashposc_>=93)) %then
                           %let _currstr6_=%trim(%quote(%left(%quote(&_currstr6_)))) %trim(%quote(%left(%quote(&_wordsub6_))));
                        %else %if (%index(%nrbquote(&_dlmc_),%str(\))) and ((%length(%trim(%quote(%left(%quote(&_currstr6_)))))>=&_slashposc_) and (&_slashposc_>=93)) %then
                           %let _currstr6_=%trim(%quote(%left(%quote(&_currstr6_))))%trim(%quote(%left(%quote(&_wordsub6_))))\;
                        %else %let _currstr6_=%trim(%quote(%left(%quote(&_currstr6_))))%str(&_dlmc_)%trim(%quote(%left(%quote(&_wordsub6_))));
                        %let _filec_=%left(%quote(&_filec_));
                        %let _filec_=%substr(%quote(&_filec_), %eval(%length(&_wordsub6_)+2), %eval(%eval(%length(&_filec_)-%length(&_wordsub6_))-1));
                     %end;
                  %end;
               %end;
               str2=trimn(left("&_currstr6_"));
               str2=tranwrd(str2, '¸', "'");
               str2=tranwrd(str2, '¹', '"');
               str2=tranwrd(str2, 'Â', '%');
               str2=tranwrd(str2, 'À', '(');
               str2=tranwrd(str2, 'Á', ')');
               %if (&_lines6_ eq 1) %then %do;
                  put '|' @6 str2 @100 '|';
               %end;
               %else %do;
                  put '|'  @6 str2 @100 '|';
               %end;
               %let _lines6_=%eval(&_lines6_+1);
            %end;
            str2=trimn(left("&_filec_"));
            str2=tranwrd(str2, '¸', "'");
            str2=tranwrd(str2, '¹', '"');
            str2=tranwrd(str2, 'Â', '%');
            str2=tranwrd(str2, 'À', '(');
            str2=tranwrd(str2, 'Á', ')');
            %if (&_lines6_ eq 1) %then %do;
               put '|' @6 str2 @100 '|';
            %end;
            %else %do;
               put '|' @6 str2 @100 '|';
            %end;
            %if (%length(%qscan(%quote(&outfile), %eval(&_nfilec_+1), %str(|)))) %then %do;
               put '|' 98*' ' '|';
            %end;
         %end;
      put '|' 36*'-' '<-- End of Files Created -->' 35*'-' @100 '|';
      put '|' 98*'-' '|';
      %end; 
      %if (%length(%nrbquote(&comment)) gt 3) %then %do;
         put '|' 37*'-' '<-- Start of Comments -->' 37*'-' @100 '|';
         str1="Comments: "; put '| '  str1 @100 '|';
         %if (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&comment))))), %str(%()) eq 1) and
             (%index(%nrbquote(%trim(%nrbquote(%left(%nrbquote(%sysfunc(reverse(%nrbquote(&comment)))))))), %str(%))) eq 1) %then %do;
            %if (%sysfunc(rxmatch(%sysfunc(rxparse($(1))),%nrbquote(&comment))) gt 1) %then %let comment=%nrbquote(%substr(%nrbquote(&comment), 2, %eval(%length(%nrbquote(&comment))-2)));
            %else %let comment=%nrbquote(%substr(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&comment))))), 2, %eval(%length(%nrbquote(%trim(%nrbquote(%left(%nrbquote(&comment))))))-2)));
         %end;
         %if ((%index(%nrbquote(&comment),%str(%')) and %index(%nrbquote(&comment),%str(%')<2))
                or (%index(%nrbquote(&comment),%str(%")) and  %index(%nrbquote(&comment),%str(%")) lt 2)) %then %do;
            %let comment=%nrbquote(%sysfunc(dequote(&comment)));
         %end;
         %let comment=%bquote(%sysfunc(tranwrd(%nrbquote(&comment), %str(%(), %str(À))));
         %let comment=%bquote(%sysfunc(tranwrd(%nrbquote(&comment), %str(%)), %str(Á))));
         %let comment=%bquote(%sysfunc(tranwrd(%nrbquote(&comment), %str(%%), %str(Â))));
         %let comment=%bquote(%sysfunc(tranwrd(%nrbquote(&comment), %str(%'), %str(¸))));
         %let comment=%bquote(%sysfunc(tranwrd(%nrbquote(&comment), %str(%"), %str(¹))));
         %let comment=%qcmpres(&comment);
         %let _ncomm_=0;
         %do %while(%length(%qscan(%quote(&comment), %eval(&_ncomm_+1), %str(|))));
            %let _ncomm_=%eval(&_ncomm_+1);
            %let _commitem_=%qscan(%quote(&comment), &_ncomm_, %str(|));
            %if (%index(%nrbquote(%sysfunc(reverse(%nrbquote(&_commitem_)))), %str(;)) ne 1) %then %let _commitem_=&_commitem_%str(;); 
            /*******loop 1 ******/
            %if (%index(%nrbquote(&_commitem_),%str(\))) %then %do;
               %let _dlmcomm_=%str(\);
            %end;
            %else %let _dlmcomm_=%str( );
            %let _lines7_=1;
            %do %while(%length(&_commitem_)>93);
               %let _substr7_=%substr(%quote(%left(%quote(&_commitem_))), 1, 93);
               %if (%quote(%substr(%quote(%left(%quote(&_commitem_))), 94, 1)) eq %quote(&_dlmcomm_)) %then %do;
                  %let _commitem_=%substr(%quote(%left(%quote(&_commitem_))), 94, %eval(%length(%left(%quote(&_commitem_)))-93));
                  %let _currstr7_=&_substr7_;
               %end;
               %else %do;
                  %let _currstr7_=; %let _subscnt7_=0;
                  %do %while(%length(%qscan(%quote(&_substr7_), %eval(&_subscnt7_+1), %str(&_dlmcomm_))));
                     %let _subscnt7_=%eval(&_subscnt7_+1);
                     %let _wordsub7_=%qscan(%quote(&_substr7_), &_subscnt7_, %str(&_dlmcomm_));
                     %if (%length(%quote(%qscan(%quote(&_substr7_), %eval(&_subscnt7_+1), %str(&_dlmcomm_))))) %then %do;
                        %if (%quote(&_dlmcomm_) eq %quote(\)) %then
                           %let _currstr7_=%trim(%quote(%left(%quote(&_currstr7_))))%trim(%quote(%left(%quote(&_wordsub7_))))%str(&_dlmcomm_);
                        %else %let _currstr7_=%trim(%quote(%left(%quote(&_currstr7_))))%str(&_dlmcomm_)%trim(%quote(%left(%quote(&_wordsub7_))));
                        %let _commitem_=%left(%quote(&_commitem_));
                        %let _commitem_=%substr(%quote(&_commitem_), %eval(%length(&_wordsub7_)+2), %eval(%eval(%length(&_commitem_)-%length(&_wordsub7_))-1));
                     %end;
                  %end;
               %end;
               str2=trimn(left("&_currstr7_"));
               str2=tranwrd(str2, '¸', "'");
               str2=tranwrd(str2, '¹', '"');
               str2=tranwrd(str2, 'Â', '%');
               str2=tranwrd(str2, 'À', '(');
               str2=tranwrd(str2, 'Á', ')');
               %if (&_lines7_ eq 1) %then %do;
                  put '|' @6 str2 @100 '|';
               %end;
               %else %do;
                  put '|'  @6 str2 @100 '|';
               %end;
               %let _lines7_=%eval(&_lines7_+1);
            %end;
            str2=trimn(left("&_commitem_"));
            str2=tranwrd(str2, '¸', "'");
            str2=tranwrd(str2, '¹', '"');
            str2=tranwrd(str2, 'Â', '%');
            str2=tranwrd(str2, 'À', '(');
            str2=tranwrd(str2, 'Á', ')');
            %if (&_lines7_ eq 1) %then %do;
               put '|' @6 str2 @100 '|';
            %end;
            %else %do;
               put '|' @6 str2 @100 '|';
            %end;
            %if (%length(%qscan(%quote(&comment), %eval(&_ncomm_+1), %str(|)))) %then %do;
            put '|' 98*' ' '|';
            %end;
         %end;
      put '\' 38*'-' '<-- End of Comments -->' 37*'-' @99 '*/';
      %end;
   end;
   if linecontent ne ' ' then do;
      atposition=length(linecontent)-length(trimn(left(linecontent)));
      put @atposition linecontent;
   end;
run;
%if (%index(%quote(%upcase(&tofile)), T)) %then %do;
   proc datasets library=work nolist;
        delete _tmp1_;
   run;quit;
%end;
%let syslast=&_tmplast_;
options ls=&linesize ps=&pagesize;
%mend GenHeader;